﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace Golos.Polls.PollCache
{
    [Serializable]
    public class UserAnswerInfo
    {
        public Guid UserId { get; private set; }
        public Guid QuestionId { get; private set; }
        public Guid AnswerId { get; private set; }
        public DateTime UtcDateTime { get; private set; }

        public UserAnswerInfo(Guid userId, Guid questionId, Guid answerId)
        {
            UserId = userId;
            QuestionId = questionId;
            AnswerId = answerId;
        }

        public UserAnswerInfo(Guid userId, Guid questionId, Guid answerId, DateTime utcDateTime)
        {
            UserId = userId;
            QuestionId = questionId;
            AnswerId = answerId;
            UtcDateTime = utcDateTime;
        }

        public byte[] Serialize()
        {
            MemoryStream stream = new MemoryStream();
            BinaryFormatter bFormatter = new BinaryFormatter();
            bFormatter.Serialize(stream, this);
            stream.Close();
            return stream.ToArray();
        }

        public static UserAnswerInfo Deserialize(Stream stream)
        {
            BinaryFormatter bFormatter = new BinaryFormatter();
            UserAnswerInfo userAnswerInfo = (UserAnswerInfo)bFormatter.Deserialize(stream);
            stream.Close();
            return userAnswerInfo;
        }
    }
}
